package com.prs.crm.action.fs;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.annotation.Clew;
import com.prs.crm.domain.crm.CustomerLevel;
import com.prs.crm.domain.fs.PayWay;
import com.prs.crm.service.fs.PayWayService;
import com.prs.crm.service.sys.LogService;

public class PayWayAction extends BaseAction {
	private PayWay payWay;
	private PayWayService payWayService;
	private PaginationSupport pagination;
	private Integer[] ids;
	private LogService logService;

	@Action("listPayWay")
	public String listPayWay() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				PayWay.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPayWayService().listByPage(criteria,
				pagination));
		return SUCCESS;
	}

	@Action("editPayWay")
	public String editPayWay() {
		return SUCCESS;
	}

	@Clew(results = { "success" })
	@Action(value = "savePayWay", results = {
			@Result(name = "success", type = "redirect", location = "listPayWay"),
			@Result(name = "error", type = "chain", location = "editPayWay") })
	public String savePayWay() {
		if (payWay.getName() == null || "".equals(payWay.getName().trim())) {
			addActionError("支付方式不能为空");
			return ERROR;
		}
		if (this.getLogService().getSearchName(PayWay.class, payWay.getName())) {
			this.addActionError("名称已经存在");
			return ERROR;
		}
		this.getPayWayService().save(payWay);
		this.setPrompt("提交付款方式成功");
		return SUCCESS;
	}

	@Action(value = "removePayWay", results = {
			@Result(name = "success", type = "redirect", location = "listPayWay"),
			@Result(name = "error", type = "chain", location = "listPayWay") })
	public String removePayWay() {
		if (ids == null) {
			this.addActionError("请选择要删除的付款方式");
			return ERROR;
		}
		this.getPayWayService().batchRemove(ids);
		return SUCCESS;
	}

	public PayWay getPayWay() {
		return payWay;
	}

	public void setPayWay(PayWay payWay) {
		this.payWay = payWay;
	}

	public PayWayService getPayWayService() {
		return payWayService;
	}

	public void setPayWayService(PayWayService payWayService) {
		this.payWayService = payWayService;
	}

	public PaginationSupport getPagination() {
		return pagination;
	}

	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public Integer[] getIds() {
		return ids;
	}

	public void setIds(Integer[] ids) {
		this.ids = ids;
	}

	public LogService getLogService() {
		return logService;
	}

	public void setLogService(LogService logService) {
		this.logService = logService;
	}
}
